package src;

/**
 * @author Dream
 */
public class mLinkedList<E> {
    private mNode head, tail;
    private int size = 0;

    public int getSize() {
        return size;
    }

    public void addToFront(E value) {
        mNode node = new mNode(value);
        if (head == null) {
            head = node;
            tail = head;
        } else {
            node.next = head;
            head = node;
        }
        size++;
    }

    public void addToRear(E value) {
        mNode node = new mNode(value);
        if (tail == null) {
            tail = node;
            head = tail;
        } else {
            tail.next = node;
            tail = node;
        }
        size++;
    }


    /**
     * 删除头部节点
     */
    public E delTopNode() {
        if (head == null) {
            return null;
        }
        E value = (E) head.value;
        //删除头节点
        head = head.next;
        size--;
        return value;
    }

    /**
     * 查看头部节点
     */
    public E inquiryTopNode() {
        if (head == null) {
            return null;
        }
        return (E) head.value;
    }


}
